﻿using System.Collections.Generic;
using System.Linq;
using Foothill.Common;
using Foothill.Filter.Test.TestUtilities;
using Foothill.Model;
using Foothill.Service.AdService;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Foothill.Filter.Test
{
    [TestClass]
    public class AdListFilterMakeAndModelTest
    {
        private IAdListFilter _adListFilter;

        private ForSaleAd _fordMustang;
        private ForSaleAd _acuraEl;
        private ForSaleAd _acuraRsx;
        private ForSaleAd _fordTaurus;
        private ForSaleAd _toyotaCamry;
        private ForSaleAd _toyotaYaris;
        private ForSaleAd _vwJetta;
        private ForSaleAd _vwRabbit;

        private IList<ForSaleAd> _carList;

        [TestInitialize]
        public void Setup()
        {
            _adListFilter = new AdListFilter();

            _fordMustang = new ForSaleAd { AdId = 1, MakeId = (int)MakeId.Ford, ModelId = (int)ModelId.Mustang };
            _acuraEl = new ForSaleAd { AdId = 2, MakeId = (int)MakeId.Acura, ModelId = (int)ModelId.EL };
            _acuraRsx = new ForSaleAd { AdId = 3, MakeId = (int)MakeId.Acura, ModelId = (int)ModelId.RSX };
            _fordTaurus = new ForSaleAd { AdId = 4, MakeId = (int)MakeId.Ford, ModelId = (int)ModelId.Taurus };
            _toyotaCamry = new ForSaleAd { AdId = 5, MakeId = (int)MakeId.Toyota, ModelId = (int)ModelId.Camry };
            _toyotaYaris = new ForSaleAd { AdId = 6, MakeId = (int)MakeId.Toyota, ModelId = (int)ModelId.Yaris };
            _vwJetta = new ForSaleAd { AdId = 7, MakeId = (int)MakeId.VolksWagen, ModelId = (int)ModelId.Jetta };
            _vwRabbit = new ForSaleAd { AdId = 8, MakeId = (int)MakeId.VolksWagen, ModelId = (int)ModelId.Rabbit };

            _carList = new List<ForSaleAd> { _fordMustang, _acuraEl, _acuraRsx, _fordTaurus, _toyotaCamry, _toyotaYaris, _vwJetta, _vwRabbit };
        }
        
        [TestMethod]
        public void ShouldFindOnlyAcuraModels()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { IncludeAllMakes = false };
            param.AddMakeAndModel((int)MakeId.Acura, GlobalValues.AllModelId);

            IList<ForSaleAd> actual = _adListFilter.FilterSearchResultList(param, _carList);
            IList<ForSaleAd> expected = new List<ForSaleAd> { _acuraEl, _acuraRsx };

            Assert.IsTrue(actual.SequenceEqual(expected, new SimpleAdIdEqualityComparer()));
        }

        [TestMethod]
        public void ShouldFindOnlyFordMustang()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { IncludeAllMakes = false };
            param.AddMakeAndModel((int)MakeId.Ford, (int)ModelId.Mustang);

            IList<ForSaleAd> actual = _adListFilter.FilterSearchResultList(param, _carList);
            IList<ForSaleAd> expected = new List<ForSaleAd> { _fordMustang };

            Assert.IsTrue(actual.SequenceEqual(expected, new SimpleAdIdEqualityComparer()));
        }

        [TestMethod]
        public void ShouldReturnFordTaurusAndAllVolksWagenModels()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { IncludeAllMakes = false };
            param.AddMakeAndModel((int)MakeId.Ford, (int)ModelId.Taurus);
            param.AddMakeAndModel((int)MakeId.VolksWagen, GlobalValues.AllModelId);

            IList<ForSaleAd> actual = _adListFilter.FilterSearchResultList(param, _carList);
            IList<ForSaleAd> expected = new List<ForSaleAd> { _fordTaurus, _vwJetta, _vwRabbit };

            Assert.IsTrue(actual.SequenceEqual(expected, new SimpleAdIdEqualityComparer()));
        }

        [TestMethod]
        public void ShouldReturnAllCars()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { IncludeAllMakes = true };

            IList<ForSaleAd> actual = _adListFilter.FilterSearchResultList(param, _carList);
            Assert.IsTrue(actual.SequenceEqual(_carList, new SimpleAdIdEqualityComparer()));
        }
    }
}
